package com.example.myintentservice;

import android.app.IntentService;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;
import android.text.format.DateFormat;
import android.util.Log;

public class LincIntentService extends IntentService {
	
	/* 
     * Action 
     */  
    private static final String ACTION_RECV_MSG = "com.linc.intent.action.RECEIVE_MESSAGE";  
    private static final String ACTION_OTHER_MSG = "com.linc.intent.action.OTHER_MESSAGE";  
      
    /* 
     * Message 
     */  
    private static final String MESSAGE_IN="message_input";  
    private static final String MESSAGE_OUT="message_output";  
      
    private final static String Tag="---LincIntentService"; 

	public LincIntentService() {
		   super("");  
	        //Log.d(Tag, "Constructor"); 
	}
	
	 @Override  
	    public IBinder onBind(Intent intent) {   
	        Log.d(Tag, "onBind()");   
	        return super.onBind(intent);   
	    }   
	    
	    @Override  
	    public void onCreate() {   
	        Log.d(Tag, "onCreate()");   
	        super.onCreate();   
	    }   
	    
	    @Override  
	    public void onDestroy() {   
	        Log.d(Tag, "onDestroy()");   
	        super.onDestroy();   
	    }   
	    
	    @Override  
	    public void onStart(Intent intent, int startId) {   
	        Log.d(Tag, "onStart()");   
	        super.onStart(intent, startId);   
	    }   
	    
	    @Override  
	    public int onStartCommand(Intent intent, int flags, int startId) {   
	        Log.d(Tag, "onStartCommand()");   
	        return super.onStartCommand(intent, flags, startId);   
	    }   
	    
	    @Override  
	    public void setIntentRedelivery(boolean enabled) {   
	        Log.d(Tag, "setIntentRedelivery()");   
	        super.setIntentRedelivery(enabled);   
	    }  

	@Override
	protected void onHandleIntent(Intent intent) {
		// TODO Auto-generated method stub
		  Log.d(Tag, "LincIntentService is onHandleIntent!");  
	        String msgRecv = intent.getStringExtra(MESSAGE_IN);  
	        for (int i = 0; i < 5; i++) {  
	            String resultTxt = msgRecv + " "  + DateFormat.format("MM/dd/yy hh:mm:ss", System.currentTimeMillis());  
	            Intent broadcastIntent = new Intent();  
	            broadcastIntent.setAction(ACTION_RECV_MSG);  
	            broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);  
	            broadcastIntent.putExtra(MESSAGE_OUT, resultTxt);  
	            sendBroadcast(broadcastIntent);  
	            SystemClock.sleep(1000); 
	        }

	}
}
